package com.haogu.controller;

import com.haogu.pojo.Result;
import com.haogu.pojo.vo.ValidateLoginVo;
import com.haogu.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("login")
public class LoginController {
    @Autowired
    private UserService userService;

    /**
     * 获取图形验证码
     */
//    @ApiOperation(value = "获取图形验证码" , notes = "获取4位图形验证码")
//    @GetMapping("validateCode")
//    public Result validateCode(){
//        return Result.success(userService.validateCode());
//    }

    /**
     * 账号登录接口
     * @param validateLoginVo
     */
    @ApiOperation(value = "账号密码登录" , notes = "使用账号密码登录")
    @PostMapping("account")
    public Result accountLogin(@RequestBody ValidateLoginVo validateLoginVo){
        return Result.success(userService.login(validateLoginVo));
    }

    /**
     * 账号验证码登录接口
     * @param validateLoginVo
     */
    @PostMapping("loginVerificationCode")
    public Result loginVerificationCode(@RequestBody ValidateLoginVo validateLoginVo){
        return Result.success(userService.loginVerificationCode(validateLoginVo));
    }

    /**
     * 获取短信验证码
     * @param phone
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获取短信验证码" , notes = "获取4位短信验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone" , value = "电话" , defaultValue = "18143985606" , required = true)
    })
    @GetMapping("validateMessagesCode")
    public Result validateMessagesCode(String phone) throws Exception {
        return Result.success(userService.validateMessagesCode(phone));
    }

    /**
     * 短信验证码登录
     * @param validateLoginVo
     */
    @ApiOperation(value = "注册" , notes = "手机号注册")
    @PostMapping("accountMessages")
    public Result loginMessages(@RequestBody ValidateLoginVo validateLoginVo){
        return Result.success(userService.Messages(validateLoginVo));
    }
}
